<!--
 * @Author: 鲁大师 2903675921@qq.com
 * @Date: 2022-07-11 16:51:53
 * @LastEditors: 鲁大师 2903675921@qq.com
 * @LastEditTime: 2022-07-11 19:33:30
 * @FilePath: \千锋课程\js三阶段\作业\7.11作业1.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        #box{
            width: 600px;
            margin:0 auto;
        }
        th{
            width: 100px;
            text-align: center;
        }
        td{
            width: 100px;
            text-align: center;
        }
        table{
            border-collapse: collapse;
            margin-bottom: 30px;
        }
        .active{
            background-color: blue;
            color:white;
        }
        input{
            display: block;
            margin-bottom: 10px;
        }
        select{
            display: block;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>
    <div id="box">
        <table border="1">
            <tr>
              <th>id</th>
              <th>姓名</th>
              <th>性别</th>
              <th>分数</th>
              <th>等级</th>
              <th>操作</th>
            </tr>
            <tr v-for="(item,index) in list" :key="item.id" :class="{'active':item.score>=90}">
              <td>{{index+1}}</td>
              <td>{{item.name}}</td>
              <td>{{item.sex}}</td>
              <td>{{item.score}}</td>
              <td v-if="item.score>60&&item.score<=80">及格</td>
              <td v-else-if="item.score>=90">优秀</td>
              <td v-else-if="item.score<60">不及格</td>
              <td v-else-if="item.score>80&&item.score<90">良好</td>
              <td><button 
                 v-on:click="remove(index)">删除</button></td>
            </tr>
          </table>
          姓名：<input type="text" v-model.trim="name" />
          性别：<select v-model="sex">
            <option value="男">男</option>
            <option value="女">女</option>
                </select>
        分数：<input type="number" max="100" min="0" v-model="score" >
        <button @click="add"  >添加</button>
    </div>
    <script>
        new Vue({
            el: "#box",
            data: {
                flag:true, 
                name:'',
                sex:'',
                score:'',
                list: [
                    { id: 1, name: '诸葛亮', sex: '男', score: 98 },
                    { id: 2, name: '周瑜', sex: '男', score: 88 },
                    { id: 3, name: '刘阿斗', sex: '男', score: 50 },
                    { id: 4, name: '曹植', sex: '男', score: 90 },
                    { id: 5, name: '张飞', sex: '男', score: 70 },
                    { id: 6, name: '曹丕', sex: '男', score: 55 }
                ]
            },
            methods:{
                remove(index){
                    this.list.splice(index,1)
                },
                add(){
                    if (!this.name ||!this.sex || !this.score) {
                        alert('请输入完整信息')
                        return 0
                    }
                    if(this.score>100||this.score<0){
                        alert("请输入正确的分数")
                    }
                    this.list.push({
                        id:this.list.length+1,
                        name:this.name,
                        sex:this.sex,
                        score:this.score,   
                    })
                     
                    this.name=""
                    this.sex=''
                    this.score=""
                }
            },
        })
    </script>
</body>

</html>